﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Net;

namespace Web
{
    public partial class GetIp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var webClient = new WebClient())
            {
                try
                {

                    var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp");

                    var ip = Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value;

                    string[] arr = temp.Split('：');

                    var adress = arr[arr.Length - 1].Replace("</center></body></html>","");

                    TextBox1.Text = ip;

                    TextBox2.Text = adress;
                }
                catch (Exception ex)
                {
                    TextBox1.Text = ex.Message;
                }
            }
        }
    }
}